﻿using System;
using Cms.Application.Admin.Presenters;
using Cms.Application.Admin.Views;
using Cms.Web.Framework.Controls;
using iLib.Web.UI;

namespace Cms.Web.UI.Admin
{
    public partial class EditApplication : AdminPage, IEditApplicationView
    {
        private EditApplicationPresenter _presenter;

        #region IEditApplicationView Members

        public int ApplicationID
        {
            get
            {
                if (ViewState["ApplicationID"] == null)
                    ViewState["ApplicationID"] = QueryString.GetInt32ID("id");
                return (int) ViewState["ApplicationID"];
            }
        }


        public void SetApplicationID(int id)
        {
            ViewState["ApplicationID"] = id;
        }


        public string Name
        {
            get { return txtName.Text; }
            set { txtName.Text = value; }
        }


        public string Description
        {
            get { return txtDescription.Text; }
            set { txtDescription.Text = value; }
        }


        public string ContextTranslationFile
        {
            get { return "Admin/Translations/EditApplication.xml"; }
        }

        #endregion

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _presenter = new EditApplicationPresenter(this);
            HeadingText = GetText(this, ApplicationID > 0 ? "EditApplicationHeading" : "NewApplicationHeading");
            if (Page.IsPostBack)
                return;
            _presenter.Initialize();
            HeadingIcon = litIcon.Text;
            txtName.Focus();
        }


        protected void lbSave_Click(object sender, EventArgs e)
        {
            _presenter.Save();
            if (_presenter.IsValid)
                Response.Redirect("Applications.aspx");
        }
    }
}